Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #78 - Implement server side pagination and sorting for queries #2566

Closed
wants to merge 13 commits into from

Conversation

jezdez
Copy link
Member

@jezdez jezdez commented Jun 5, 2018

This was initially reported in #78 but also applies to the queries search where the list of results can become quite large depending on the number of queries and search term used.

This was originally reported in mozilla#384 and mozilla#385 and also fixes also mozilla#323 (which was not reported here initially).

It deprecates the standalone backend query search handler and client query search resource and implements redirects for those.

I believe the live paginator should also be used in more list views and the non-live paginator deprecated or outright removed. I'm not sure how Redash is handling API backward compatibility, so I erred on the side of caution and followed a deprecation policy (that could mean removing old APIs after the next version for example).

Copy link

@washort washort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+

itemsPerPage = 20,
orderByField,
orderByReverse = false,
params = {},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ...params instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, hm, maybe?

itemsPerPage: this.pageSize,
orderByField: pageOrder,
orderByReverse: pageOrderReverse,
params: this.parameters,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this.parameters have a value at this point? (I see where update() assigns to it later.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit of a kerfuffle, I'll clean this up while porting this to #2573

this.searchTerm = '';
}
this.paginator.itemsPerPage = this.pageSize;
this.paginator.params = this.parameters();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to just inline the parameters function? I found the similar name to params confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good idea.

@jezdez
Copy link
Member Author

jezdez commented Jun 5, 2018

@arikfr This is the PR I talked about recently, please let me know if you want me to explain the implementation details if needed.

Copy link
Member

@arikfr arikfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good ! some quick comments.

@@ -1,12 +1,23 @@
import moment from 'moment';
import { isString } from 'underscore';
import startsWith from 'underscore.string/startsWith';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use String's own startsWith.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about IE11 is very benevolent of you :) But I would assume Babel takes care of this for us?

@@ -1,12 +1,23 @@
import moment from 'moment';
import { isString } from 'underscore';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the React pull request gets merged before this one, we need to remember to replace this with lodash...

order = request.args.get('order', '').strip() or default_order
# and if it matches a long-form for related fields, falling
# back to the default order
selected_order = order_map.get(order, order)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use default_order as the default value here as well, just to make sure that we only get predefined values for ordering?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure good idea!

selected_order = order_map.get(order, order)
# The query may already have an ORDER BY statement attached
# so we clear it here and apply the selected order
return sort_query(results.order_by(None), selected_order)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. What would happen without this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, the all_queries class method sorts by created_at, which means we just reset it here to be able to apply the sorting according to the query parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But isn't SQLA smart enough to just replace the order_by when called again?

search=term,
drafts='true' if include_drafts else 'false'
)
return {}, 301, {'Location': new_location}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always deploy API and client side together, so maybe we can just remove this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that'd be nicer indeed. And you don't make any guarantees regarding the API stability?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really 🙄

I wonder if there are people who are using this API endpoint not in the application? 🤔

.options(
contains_eager(Query.user),
contains_eager(Query.latest_query_data),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two options calls on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, SQA generated different queries otherwise 😬

@jezdez
Copy link
Member Author

jezdez commented Jul 18, 2018

Closing in favor of #2686 which is much smaller since many of the changes here have been merged with #2573.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants